{
	template:`
	<div style="padding:0 10px 10px;">
        <a-row :gutter="16" style="margin-bottom:10px;">
            <a-col :span="24">
                <a-space style="margin-bottom:10px;">
                    <span>输入表名，提取字段，修改后可生成java模型字段。</span>
                    <a-input v-model:value="tableName" placeholder="请输入表名" />
                    <a-button type="primary" @click="initTableField">提取字段</a-button>
                </a-space>
            </a-col>
            <a-col :span="24">
                <a-table :columns="columns" :data-source="columnData" size="small" bordered :pagination="false" :scroll="{ y: 500 }">
                    <template #bodyCell="{ column, text, record }">
                        <template v-if="column.dataIndex=='name'">
                            <span>{{record[column.dataIndex]}}</span>
                        </template>
                        <template v-else-if="column.dataIndex=='type'">
                            <a-select v-model:value="record[column.dataIndex]" :options="typeOption" style="width:100%"></a-select>
                        </template>
                        <template v-else-if="column.dataIndex=='length'">
                            <a-input-number v-if="record['type']=='FieldType.STRING'" v-model:value="record[column.dataIndex]" style="width:100%" />
                            <span v-else></span>
                        </template>
                        <template v-else-if="column.dataIndex=='notnull'">
                            <a-checkbox v-model:checked="record[column.dataIndex]"></a-checkbox>
                        </template>
                        <template v-else>
                            <a-input v-model:value="record[column.dataIndex]" />
                        </template>
                    </template>
                </a-table>
            </a-col>
        </a-row>
        <div style="text-align:right;margin:10px 0;">
            <a-space>
                <span style="color:#f30;">无保存功能，请及时复制保存成文件。</span>
                <a-button :disabled="columnData.length==0" type="primary" @click="toCode">生成代码</a-button>
            </a-space>
        </div>
        <a-textarea v-model:value="codeStr" :auto-size="{ minRows: 3, maxRows: 30 }" placeholder="编辑完成可点击生成代码查看"/>
    </div>
	`,
	props: ['localeZh','param','parentVue'],
	data:function(){
		return {
		    tableName:'',
		    columnData:[],
		    columns:[
		        {title: '列名', dataIndex: 'name', width:'110px'},
		        {title: '字段名', dataIndex: 'field', width:'110px'},
		        {title: '类型', dataIndex: 'type', width:'100px'},
		        {title: '长度', dataIndex: 'length', width:'90px'},
		        {title: '非空', dataIndex: 'notnull', width:'50px',align:'center'},
		        {title: '默认值', dataIndex: 'defaultValue', width:'110px'},
		        {title: '描述', dataIndex: 'description', width:'220px'},
		        {title: '字典', dataIndex: 'dictType', width:'110px'},
		        {title: '选项', dataIndex: 'dictOption', width:'110px'},
		        {title: '数据库类型', dataIndex: 'dbType', width:'110px'}
		    ],
		    typeOption:[
		        {value:'STRING',label:'STRING'},
		        {value:'INT',label:'INT'},
		        {value:'DOUBLE',label:'DOUBLE'},
		        {value:'DATE',label:'DATE'}
		    ],
		    codeStr:''
		};
	},
	mounted(){
	},
	methods:{
	    initTableField:function(){
	        if(!this.tableName){
	            this.remind().error("请输入表名");
	            return ;
	        }
            this.requestData("action/manage/developer/getTableField",
                {"tableName":this.tableName},
                function(data){
                    if(data.code==0){
                        for(let i=0;i<data.columns.length;i++){
                            this.handleColumn(data.columns[i]);
                        }
                        this.columnData=data.columns;
                        console.log(this.columnData,this.columnData.length);
                        if(this.columnData.length==0){
                            this.remind().error("没有提取到表字段，请检查表名是否正确。");
                        }
                    }else{
                        this.remind().error(data.msg);
                    }
                }.bind(this)
            );
	    },
	    handleColumn:function(colData){
            colData.field=this.underlineToCamelCase(colData.name);
            colData.notnull=colData.notnull?true:false;
	        if(colData.type.indexOf("int")>=0)
	            colData.type="INT";
	        else if(colData.type.indexOf("float")>=0||colData.type.indexOf("double")>=0||colData.type.indexOf("decimal")>=0)
	            colData.type="DOUBLE";
	        else if(colData.type.indexOf("date")>=0||colData.type.indexOf("time")>=0)
	            colData.type="DATE";
	        else{
	            if(colData.type=='text') colData.dbType="text";
	            colData.type="STRING";
	        }
	    },
	    underlineToCamelCase:function(str) {
	        if(str){
                return str.replace(/_([a-z])/g, function(match, letter) {
                    return letter.toUpperCase();
                });
	        }else{
	            return str;
	        }
        },
        toCode:function(){
            this.codeStr='\t//此生成数据适用于已存在数据库生成模型的java代码\r\n'
            +'\t//class类注解参考\r\n'
            +'\t//@TableMeta(name="'+this.tableName+'",description="", autoCreate = false,oidField = "id",oidIncrement = true)\r\n'
            +'\t//模型类属性参考\r\n'
            +'\t//@LinkTableMeta(name="admin_oid",table=AdminLogin.class,description="所属管理员")\r\n'
            +'\t//private AdminLogin admin;\r\n'
            +'\t//生成字段\r\n';
            for(let i=0;i<this.columnData.length;i++){
                let col=this.columnData[i];
                this.codeStr+='\t@FieldMeta(name="'+col.name+'",type=FieldType.'+col.type+','
                +(col.type=='STRING'?'length='+col.length+',':'')
                +(col.dbType?'dbType="'+col.dbType+'",':'')
                +(col.dictType?'dictType="'+col.dictType+'",':'')
                +(col.dictOption?'dictType="'+col.dictOption+'",':'')
                +'description="'+col.description+'"'
                +')\r\n';
                this.codeStr+='\tprivate '+this.getJavaType(col.type)+' '+col.field+';\r\n';
            }
        },
        getJavaType:function(type){
            if(type=='STRING') return "String";
            if(type=='INT') return "Integer";
            if(type=='DOUBLE') return "Double";
            if(type=='DATE') return "Date";
        }
	}
}